package chances.epg.ui.widget.taglib;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import chances.epg.commons.utils.JSONUtils;

@SuppressWarnings("serial")
public class WidgetOptionsTag extends BodyTagSupport {

	@Override
	public int doEndTag() throws JspException {
		if (this.getBodyContent() != null) {
			String body = this.getBodyContent().getString();
			Tag parent = getParent();
			if (WidgetTag.class.isInstance(parent)){
				Map<String,Object > options = JSONUtils.toMap(body);
				((WidgetTag) parent).setOptions(JSONUtils.fromObject(options));
			}
		
		}
		return super.doEndTag();
	}

}
